﻿
module Sustainalytics.CompanySearch {

    import Common = Sustainalytics.Common;
    import Company = Sustainalytics.Company;
    import SearchBox = Sustainalytics.SearchBox;


    export class CompanySearchBoxServiceAdapter implements SearchBox.ISearchBoxService
    {
        private companySearchService: Company.ICompanyService;

        // Ctor.
        public constructor(
            private $http,
            private $q,
            private $rootScope,
            private notificationFactory,
            private staticObjects,
            private UserInfoService) {

            var ctx = this;

            ctx.companySearchService = new Company.CompanyService($http, $q, $rootScope, notificationFactory, staticObjects, UserInfoService);
        }

        // Search for items given a term and paging options
        public Search(searchData: any, skip: number, take: number): ng.IHttpPromise<any[]> {
            // get companies paged list
            var lstPromise: ng.IHttpPromise<Company.CorporateDataExtendedDto[]> = this.companySearchService.search(searchData, skip, take);
            return lstPromise;
        }
    }


    // get/create company search module
    var companySearchModule = angular.module('Sustainalytics.CompanySearch');

    // register company search service adapter angular service factory
    companySearchModule.service('CompanySearchBoxServiceAdapter',
        ['$http', '$q', '$rootScope', 'notificationFactory', 'staticObjects', 'UserInfoService', CompanySearchBoxServiceAdapter]);
}